//
//  SingIn2Controller.m
//  MY Project For Sport
//
//  Created by admin on 16/2/13.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "SingIn2Controller.h"
#import "NetworkingHandlerOfBlock.h"
#import "ModelOfSignIn.h"
#import "SignInOfCell.h"
#import "SignInWebController.h"

#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667


@interface SingIn2Controller ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *array;



@end

@implementation SingIn2Controller

-(void)dealloc {
    [_ID release];
    [_tableView release];
    [_array release];
    
    [super dealloc];

}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self handledata];
    [self createTableView];
    
    
}

- (void)handledata {
    
    self.array = [NSMutableArray array];
    
    
    if ([self.ID isEqualToString:@"1"]) {
       
        NSString *str1 = @"http://platform.sina.com.cn/sports_client/team_hot?app_key=2586208540&_version__=3.2.1.01&__os__=android&type=2&num=50&client_deviceid=e1626cc2f63146d9302c32f415dfedf0";
  
        [NetworkingHandler networkingWithUrl:str1 completeHandle:^(NSURLResponse *response, NSData *data, id result) {
            
            NSDictionary *dic = [result objectForKey:@"result"];
            NSArray *array = [dic objectForKey:@"data"];
            for (NSDictionary *dict in array) {
                ModelOfSignIn *model = [[ModelOfSignIn alloc] init];
                
                [model setValuesForKeysWithDictionary:dict];
                
                [self.array addObject:model];
                
                [model release];
                
                
            }
            
            [self.tableView reloadData];
            
            
        }];
        
        
    } else {
    
    
    
    NSString *str = @"http://platform.sina.com.cn/sports_client/team_hot?app_key=2586208540&_version__=3.2.1.01&__os__=android&type=1&num=50&client_deviceid=e1626cc2f63146d9302c32f415dfedf0";
    
    
    [NetworkingHandler networkingWithUrl:str completeHandle:^(NSURLResponse *response, NSData *data, id result) {
        
        NSDictionary *dic = [result objectForKey:@"result"];
        NSArray *array = [dic objectForKey:@"data"];
        for (NSDictionary *dict in array) {
            ModelOfSignIn *model = [[ModelOfSignIn alloc] init];
            
            [model setValuesForKeysWithDictionary:dict];
            
            [self.array addObject:model];
            
            [model release];
            
        }
        
        [self.tableView reloadData];
        
    }];
    
    }
    
}


- (void)createTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    
    [self.view addSubview:self.tableView];
    [_tableView release];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerClass:[SignInOfCell class] forCellReuseIdentifier:@"poolForSingIn"];


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


    return self.array.count;


}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    SignInOfCell *cell = [tableView dequeueReusableCellWithIdentifier:@"poolForSingIn"];
    
    ModelOfSignIn *model = [self.array objectAtIndex:indexPath.row];
    
    [cell passModelForSignIN:model];

    return cell;


}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return self.view.frame.size.height / 10;


}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    SignInWebController *web = [[SignInWebController alloc] init];
    
    
    [self.navigationController pushViewController:web animated:YES];
    
    
    [web release];



}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
